package tec.stan.ling.topo.graph.palette;

import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteRoot;

import tec.stan.ling.core.top.model.Device;
import tec.stan.ling.core.top.model.Subnet;
import tec.stan.ling.topo.ICons;
import tec.stan.ling.topo.TopoPlugin;

/**
 * Create a PaletteRoot for TopoViewEidtor
 * 
 * 为TopoViewEidtor构造PaletteRoot。
 * 注意该类引用单态模式，PaletteRoot也只有一个实例。
 * 
 * @author Stan 张新潮
 * @since 2009-12-31
 */
public class TopoPaletteFactory {

	private PaletteRoot platteRoot;

	private static TopoPaletteFactory instance;

	private TopoPaletteFactory() {
		platteRoot = new PaletteRoot();
		platteRoot.add(createShapesDrawer());
	}

	public static TopoPaletteFactory getInstance() {
		if (instance == null) {
			instance = new TopoPaletteFactory();
		}
		return instance;
	}

	public PaletteRoot getPalette() {
		return platteRoot;
	}

	private PaletteContainer createShapesDrawer() {
		PaletteDrawer componentsDrawer = new PaletteDrawer("Topo Element");
		
		//create Subnet node
		PaletteObject oSubnet = new PaletteObject(Subnet.class);
		CombinedTemplateCreationEntry testComponent = new CombinedTemplateCreationEntry(
				"Subnet", "Create a Subnet", oSubnet,
				new PaletteCreationFactory(oSubnet), TopoPlugin
						.getImageDescriptor(ICons.SUBNET_TREE), TopoPlugin
						.getImageDescriptor(ICons.SUBNET_TREE));
		componentsDrawer.add(testComponent);

		//create NetElement node
		PaletteObject oNetElement = new PaletteObject(Device.class);
		CombinedTemplateCreationEntry testInputComponent = new CombinedTemplateCreationEntry(
				"Net Element", "Create a Net Element", oNetElement,
				new PaletteCreationFactory(oNetElement), TopoPlugin
						.getImageDescriptor(ICons.ELEMENT_TREE), TopoPlugin
						.getImageDescriptor(ICons.ELEMENT_TREE));
		componentsDrawer.add(testInputComponent);
		
		return componentsDrawer;
	}
}
